﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.Configuration;

namespace WebApplication3.Models
{
	public class SFCreateOrderModel
	{
		[Required]
		public int dev_id { get; set; }

		[Required]
		public string shop_id { get; set; }
		public int shop_type { get; set; }
		[Required]
		public string shop_order_id { get; set; }
		[Required]
		public string order_source { get; set; }

		public string order_sequence { get; set; }

		public int lbs_type { get; set; }
		[Required]
		public int pay_type { get; set; }
		public int receive_user_money { get; set; }
		[Required]
		public int order_time { get; set; }
		[Required]
		public long push_time { get; set; }
		[Required]
		public int is_appoint { get; set; }
		public int expect_time { get; set; }
		public string remark { get; set; }
		[Required]
		public int version { get; set; }

		[Required]
		public ReceiveModel receive { get; set; }
		public ShopModel shop { get; set; }

		[Required]
		public OrderDetailModel order_detail { get; set; }
		public int return_flag { get; set; }

		public int rider_pick_method { get; set; }


		public SFCreateOrderModel( ) {
			this.shop_order_id = DateTime.Now.ToString("yyyyMMddHHmmssFFFF");
			this.order_source = "对接";
			this.is_appoint = 0;

			this.shop_type = 1;
			this.lbs_type = 2;

			this.pay_type = 1;

			this.return_flag = 1;
			this.rider_pick_method = 1;

			////从配置文件读取
			this.dev_id =ConstData.DevId;

			this.shop_id = ConstData.ShopId;

			this.version = 17;
		 
			this.push_time = ConvertDateTimeInt(DateTime.Now);
			this.order_time= ConvertDateTimeInt(DateTime.Now);

		}

		/// <summary>
		/// DateTime时间格式转换为10位不带毫秒的Unix时间戳
		/// </summary>
		/// <param name="time"> DateTime时间格式</param>
		/// <returns>Unix时间戳格式</returns>
		public   int ConvertDateTimeInt(System.DateTime time)
		{
			System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
			return (int)(time - startTime).TotalSeconds;
		}

	}
	
	/// <summary>
	/// POSTDATA['shop']
	/// </summary>
	public class ShopModel
	{
		[Required]

		public string shop_name { get; set; }
		[Required]
		public string shop_phone { get; set; }
		[Required]
		public string shop_address { get; set; }
		public string shop_lng { get; set; }
		public string shop_lat { get; set; }

	}

	/// <summary>
	/// POSTDATA['receive']
	/// </summary>
	public class ReceiveModel
	{
		[Required]

		public string user_name { get; set; }
		[Required]
		public string user_phone { get; set; }
		[Required]
		public string user_address { get; set; }
		[Required]
		public string user_lng { get; set; }
		[Required]
		public string user_lat { get; set; }

	}

	public class OrderDetailModel
	{
		[Required]

		public int total_price { get; set; }
		public int product_type { get; set; }
		public int user_money { get; set; }
		public int shop_money { get; set; }
		[Required]
		public int weight_gram { get; set; }
		public int volume_litre { get; set; }
		public int delivery_money { get; set; }
		[Required]
		public int product_num { get; set; }
		[Required]
		public int product_type_num { get; set; }
		[Required]
		public List<ProductDetailModel> ProductDetails { get; set; }


	}

	public class ProductDetailModel
	{
		[Required]

		public string product_name { get; set; }
		public int product_id { get; set; }
		[Required]
		public int product_num { get; set; }
		public int product_price { get; set; }
		public string product_unit { get; set; }
		public string product_remark { get; set; }
		public string item_detail { get; set; }


		public ProductDetailModel() {

			 

		}

	}
}
